package c.mars.tower_of_hanoi.menu;

import c.mars.tower_of_hanoi.game.GameActivity;
import android.content.Context;
import android.content.Intent;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;

public class MenuGLSurfaceView extends GLSurfaceView {
	
	private final String TAG = getClass().getName();
	
	Renderer mRenderer;
	
	public MenuGLSurfaceView(Context context) {
		super(context);
		
		setEGLContextClientVersion(2);
		
//		Create and remember Renderer for drawing on the GLSurfaceView
		mRenderer = new MenuRenderer();
		setRenderer(mRenderer);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent e) {
		
		switch (e.getAction()) {
		case MotionEvent.ACTION_DOWN :
			
//			Temporary we check just vertical stripe of screen on touch event, not buttons
			float x = e.getX();
			float width = getWidth();
			float menuButtonStep = width/3;
			GameActivity.rodsCount = (x < menuButtonStep ? 3 : (x > 2*menuButtonStep) ? 5 : 4);
			
			Log.w(TAG, String.format("onTouchEvent:ACTION_DOWN rodsCount=%d", GameActivity.rodsCount));
			
			Intent intent = new Intent(getContext().getApplicationContext(), c.mars.tower_of_hanoi.game.GameActivity.class);
			getContext().startActivity(intent);
		}

		return true;
	}

}
